package com.itheima.demo3;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author chihb
 * @create-time 2024/7/2 18:10
 * @description
 */
public class Test {
    public static void main(String[] args) {
        LocalDate startDate = LocalDate.of(2022, 2, 3);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要查询的年份和月份，且必须是2022年2月之后的月份");
        String currentDate = sc.next() + "-01";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM");
        LocalDate endMonth = LocalDate.parse(currentDate);
        LocalDate endDate = endMonth;
        //拿到这个月份的最后一天日子，作为截至日期
        endDate = endDate.plusMonths(1).minusDays(1);
        //从起始日子，一直拿到截止日子的全部日子，方便标记哪些是休息，方便后面进行信息查询
        List<Day> days = new ArrayList<>();
        while (startDate.isBefore(endDate)) {
            Day day = new Day(startDate);
            days.add(day);
            startDate = startDate.plusDays(1);
        }
        //System.out.println("起点开始的全部日子"+days);
        List<Day> currentDayRest = new ArrayList<>();
        for (int i = 0; i < days.size(); i += 3) {
            Day day = days.get(i);
            day.setFlag(true);
        }
        for (int i = 0; i < days.size(); i++) {
            Day day = days.get(i);
            if (day.getDate().isBefore(endMonth)) {
                continue;
            }
            currentDayRest.add(day);
            day.printInfo();
        }
        //找到哪些日子是周末
        currentDayRest.stream().filter(d -> (d.getDate().getDayOfWeek().getValue() == 6 || d.getDate().getDayOfWeek().getValue() == 7) && d.isFlag())
                .forEach(d->{
                    System.out.println(d);
                    if(d.getDate().getDayOfWeek().getValue()==6){
                        System.out.println("周六");
                    }else {
                        System.out.println("周日");
                    }
                });
    }

}
